#ifndef SATELLITE_H
#define SATELLITE_H

#include "common.h"
#include "vector3d.h"
#include "quaternion.h"
#include "attitude_controller.h"
#include "ion_thruster.h"
#include "gnss_parser.h"

// 卫星状态
typedef struct {
    // 轨道参数
    Vector3D position;          // 位置 (ECEF坐标系)
    Vector3D velocity;          // 速度 (m/s)
    double mass;                // 质量 (kg)
    
    // 姿态参数
    Quaternion attitude;        // 姿态四元数
    Vector3D angular_velocity;    // 角速度 (rad/s)
    Vector3D angular_acceleration; // 角加速度 (rad/s²)
    
    // 惯性参数
    double inertia_tensor[3][3];  // 惯性张量 (kg·m²)
    double inertia_inverse[3][3]; // 逆惯性张量
    
    // 子系统
    AttitudeController attitude_controller;
    IonThruster thruster[4];      // 4个离子发动机
    GNSS_Receiver gnss_receiver;
    
    // 状态
    double timestamp;
    bool is_active;
    char name[32];
} Satellite;

// 函数声明
ErrorCode satellite_init(Satellite* sat, const char* name);
ErrorCode satellite_update(Satellite* sat, double dt);
ErrorCode satellite_set_target_attitude(Satellite* sat, Quaternion target);
ErrorCode satellite_get_state_string(Satellite* sat, char* buffer, size_t size);

// 动力学计算
ErrorCode satellite_calculate_dynamics(Satellite* sat, double dt);
ErrorCode satellite_apply_torque(Satellite* sat, Vector3D torque, double dt);
ErrorCode satellite_apply_force(Satellite* sat, Vector3D force, double dt);

// 姿态机动
ErrorCode satellite_point_to_direction(Satellite* sat, Vector3D direction);
ErrorCode satellite_stabilize(Satellite* sat);
ErrorCode satellite_slew_maneuver(Satellite* sat, Quaternion target, double duration);

// 传感器模拟
ErrorCode satellite_update_gnss(Satellite* sat);
ErrorCode satellite_update_sensors(Satellite* sat);

// 打印状态
void satellite_print_status(Satellite* sat);
void satellite_print_orbit(Satellite* sat);
void satellite_print_attitude(Satellite* sat);

#endif // SATELLITE_H
